package com.code2roc.xhood.model;

import java.util.HashMap;
import java.util.stream.Collectors;

public class ClassMapping {
    private HashMap<String,String> classPositionMap;
    private HashMap<String,HashMap<String,String>> obscureRelationMap = new HashMap<>();

    public ClassMapping(){
        classPositionMap = ClassRelationManage.getClassPositionMap();
        for (String position:classPositionMap.values().stream().distinct().collect(Collectors.toList())) {
            obscureRelationMap.put(position,new HashMap<>());
        }
    }

    public boolean check(String className,String originalName){
        String position = classPositionMap.get(className);
        HashMap<String,String> obsucreMap = obscureRelationMap.get(position);
        return obsucreMap.containsKey(originalName);
    }

    public void put(String className,String originalName,String obscureName){
        String position = classPositionMap.get(className);
        HashMap<String,String> obsucreMap = obscureRelationMap.get(position);
        obsucreMap.put(originalName,obscureName);
    }

    public String get(String className,String originalName){
        String position = classPositionMap.get(className);
        HashMap<String,String> obsucreMap = obscureRelationMap.get(position);
        return obsucreMap.get(originalName);
    }

    public HashMap getObsucreMap(String className){
        String position = classPositionMap.get(className);
        HashMap<String,String> obsucreMap = obscureRelationMap.get(position);
        return obsucreMap;
    }
}
